package miiteen.hb.webservice.service;

import com.HB2012.client.BasicHttpBinding_IHB2012APIStub;
import miiteen.core.result.ResultMessage;
import miiteen.hb.webservice.beans.FileListResponse;
import miiteen.hb.webservice.util.ResponseUtil;
import org.dom4j.DocumentException;
import org.springframework.stereotype.Service;

import java.rmi.RemoteException;
import java.util.List;

@Service
public class ApiService {

    private BasicHttpBinding_IHB2012APIStub binding;

    public ApiService() {
        try {
            binding = (com.HB2012.client.BasicHttpBinding_IHB2012APIStub)
                    new com.HB2012.client.HB2012APIWcfServiceLocator().getBasicHttpBinding_IHB2012API();
            binding.setTimeout(60000);
        } catch (javax.xml.rpc.ServiceException jre) {
            if (jre.getLinkedCause() != null)
                jre.getLinkedCause().printStackTrace();
            throw new junit.framework.AssertionFailedError("JAX-RPC ServiceException caught: " + jre);
        }
    }

    /**
     * 获取文件列表信息
     *
     * @param applicationName
     * @param pageNum
     * @param pageSize
     * @return
     * @throws DocumentException
     * @throws RemoteException
     */
    public FileListResponse getALLCommonFileList(String applicationName, int pageNum, int pageSize) throws DocumentException, RemoteException {
        return getALLCommonFileList(applicationName, pageNum, pageSize, "", "", "兰关动态");
    }


    /**
     * 获取文件列表信息
     *
     * @param applicationName
     * @param startRowIndex
     * @param maximumRows
     * @param startTime
     * @param endTime
     * @param taskTitle
     * @return
     * @throws DocumentException
     * @throws RemoteException
     */
    public FileListResponse getALLCommonFileList(String applicationName, Integer startRowIndex, Integer maximumRows, String startTime, String endTime, String taskTitle) throws DocumentException, RemoteException {
        String responseStr = binding.getALLCommonFileList(applicationName, startRowIndex, maximumRows, startTime, endTime, taskTitle);
        return ResponseUtil.toFileListResponse(responseStr);
    }
}
